<?php


/*
=====================================================
 Generic Toolbox - by Carl Wells
-----------------------------------------------------
-----------------------------------------------------
 Copyright (c) 2009 Carl Wells
=====================================================
 THIS IS COPYRIGHTED SOFTWARE
 PLEASE READ THE LICENSE AGREEMENT
=====================================================
 File: system/core/promotion.class.php
-----------------------------------------------------
The Object to represent a promotion
It contains getters/setters for all properties of a promotion

=====================================================
*/


class Promotion {
	var $sector;
	var $category;
	var $nameOfPromotion; // STRING
	var $promotionalItems; // ARRAY
	var $images; // array;
	var $extras;
	var $subcategory;
	var $deliveryCost;
	var $startDate;
	var $endDate;
	var $menublank;
	
	
	
	function Promotion(){
			include_once("promotionalItem.class.php");
			include_once("promotionalImage.class.php");
			$this->images =  array();
	}
	function getPromotionName(){
		return $this->nameOfPromotion;
	}
	
	function setPromotionName($nameOfPromo){
		$this->nameOfPromotion = $nameOfPromo;
	}
	function setSector($sector){
		$this->sector = $sector;
	}
	function getSector(){
		return $this->sector;
	}
	
	function setCategory($category){
		$this->category = $category;
	}
	function getCategory(){
		return $this->category;
	}
	
	function getPromotionalItems(){
	return $this->promotionalItems;
	}
	
	function addPromotionalItems($chosenItems){
		$this->promotionalItems = $chosenItems;
	}
	
	
	// images are stored in the database as a semi-colon (;) seperated string
	// for ease of use I'm storing them as an array;
	function addImages($images, $promoId) {
	$imageArray = explode(";", $images);

		foreach ( $imageArray as $key => $val ){
			$image = new PromotionalImage();
			$image->setPromoId($promoId);
			$image->setImageName($val);
			$this->images[] = $image;
		}
	}
	
	function getImages(){
		return $this->images;
		}
	
	
	
	function getNumberOfImages(){
		return count($this->images);
	}
	
	
	function addPromotion($string){
		$SESS = new Session();
		$promotionalItems = $SESS->unserializeObject($string);
		$this->promotionalItems = $promotionalItems;
	
	}
	
	function addExtras($string){
		$SESS = new Session();
		$extras = $SESS->unserializeObject($string);
		$this->extras = $extras;
	}
	function getPromotionalExtras(){
		return $this->extras;
	}
	
	function setSubCategory($subCategory) {
		$this->subcategory = $subCategory;
	}
	function getSubCategory() {
		return $this->subcategory;
	}
	function getDeliveryCost(){
		return $this->deliveryCost;
	}
	
	function setDeliveryCost($cost){
		$this->deliveryCost = $cost;
	}
	
	
	// retrieves a promotion from the database and creates a promotion object
	// from the data
	function getPromotion($category, $promotion){
    require_once(SITEBASE."system/db/dbPromo.class.php");
    $DB = new DbPromo();
    
    $sql = " SELECT * FROM `promotions` WHERE `id` = ".$promotion." LIMIT 0 , 30 ";
    
    $result = $DB->selectQuery($sql);
    
    while ($array = mysql_fetch_array($result)){
    
    	$this->setSector($array['sector']);
    	$this->setCategory($array['category']);
    
    	$this->setPromotionName($array['nameOfPromotion']);
    	$this->addPromotionalItems($array['promotionalItems']);
    	
    	$this->addImages($array['promotionalImages'], $array['id']);
    	
    	$this->setSubCategory($array['subcategory']);
    	
    	$this->addExtras($array['extras']);
    	
    	$this->menublank = $array['menublank'];
    	
    	// delivery cost is empty currently
    	// it will be calculated at the end of the process
    	$this->setDeliveryCost($array['deliveryCost']);
    	
    }
	
	
	}
	
	function getInfo(){
		return "This is where the info goes";
	}
	

}

?>